using System;
using System.Collections;
using System.DirectoryServices;

namespace BEGDC.CC.Entity
{
	#region SystemPermission

	/// <summary>
	/// SystemPermission object for NHibernate mapped table 'SystemPermission'.
	/// </summary>
	[Serializable]
	public class SystemPermission : System.IComparable
		{
		#region Member Variables
		
		protected int _id;
		protected int _systemFunctionID;
		protected int _roleID;
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public SystemPermission() { }

		public SystemPermission( int systemFunctionID, int roleID )
		{
			this._systemFunctionID = systemFunctionID;
			this._roleID = roleID;
		}

		#endregion

		#region Public Properties

		public int Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public int SystemFunctionID
		{
			get { return _systemFunctionID; }
			set { _systemFunctionID = value; }
		}

		public int RoleID
		{
			get { return _roleID; }
			set { _roleID = value; }
		}

        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public int CompareTo(object obj)
        {
			if (!(obj is SystemPermission))
				throw new InvalidCastException("This object is not of type SystemPermission");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((SystemPermission)obj).Id);
					break;
				case "SystemFunctionID":
					relativeValue = this.SystemFunctionID.CompareTo(((SystemPermission)obj).SystemFunctionID);
					break;
				case "RoleID":
					relativeValue = this.RoleID.CompareTo(((SystemPermission)obj).RoleID);
					break;
                default:
                    goto case "Id";
			}
            if (SystemPermission.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
